package com.kfdx.dc.controller;

import com.kfdx.dc.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kfdx.dc.common.annotation.Log;
import com.kfdx.dc.common.core.controller.BaseController;
import com.kfdx.dc.common.core.domain.AjaxResult;
import com.kfdx.dc.common.enums.BusinessType;
import com.kfdx.dc.domain.DcClassInfo;
import com.kfdx.dc.service.IDcClassInfoService;
import com.kfdx.dc.common.utils.poi.ExcelUtil;
import com.kfdx.dc.common.core.page.TableDataInfo;

/**
 * 分类信息管理Controller
 *
 * @author cx
 * @date 2024-09-23
 */
@Api("分类信息管理")
@RestController
@RequestMapping("/dishclass/info")
public class DcClassInfoController extends BaseController
{
    @Autowired
    private IDcClassInfoService dcClassInfoService;

    /**
     * 查询分类信息管理列表
     */
    @ApiOperation("查询分类信息管理列表")
    @PreAuthorize("@ss.hasPermi('dishclass:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcClassInfo dcClassInfo)
    {
        startPage();
        List<DcClassInfo> list = dcClassInfoService.selectDcClassInfoList(dcClassInfo);
        return getDataTable(list);
    }

    /**
     * 导出分类信息管理列表
     */
    @ApiOperation("导出分类信息管理列表")
    @PreAuthorize("@ss.hasPermi('dishclass:info:export')")
    @Log(title = "分类信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcClassInfo dcClassInfo)
    {
        List<DcClassInfo> list = dcClassInfoService.selectDcClassInfoList(dcClassInfo);
        ExcelUtil<DcClassInfo> util = new ExcelUtil<DcClassInfo>(DcClassInfo.class);
        util.exportExcel(response, list, "分类信息管理数据");
    }

    /**
     * 获取分类信息管理详细信息
     */
    @ApiOperation("获取分类信息管理详细信息")
    @PreAuthorize("@ss.hasPermi('dishclass:info:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return success(dcClassInfoService.selectDcClassInfoByClassId(classId));
    }

    /**
     * 新增分类信息管理
     */
    @ApiOperation("新增分类信息管理")
    @PreAuthorize("@ss.hasPermi('dishclass:info:add')")
    @Log(title = "分类信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcClassInfo dcClassInfo)
    {
        dcClassInfo.setCreateTime(DateUtils.getNowDate());
        return toAjax(dcClassInfoService.insertDcClassInfo(dcClassInfo));
    }

    /**
     * 修改分类信息管理
     */
    @ApiOperation("修改分类信息管理")
    @PreAuthorize("@ss.hasPermi('dishclass:info:edit')")
    @Log(title = "分类信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcClassInfo dcClassInfo)
    {
        dcClassInfo.setUpdateTime(DateUtils.getNowDate());
        return toAjax(dcClassInfoService.updateDcClassInfo(dcClassInfo));
    }

    /**
     * 删除分类信息管理
     */
    @ApiOperation("删除分类信息管理")
    @PreAuthorize("@ss.hasPermi('dishclass:info:remove')")
    @Log(title = "分类信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
        return toAjax(dcClassInfoService.deleteDcClassInfoByClassIds(classIds));
    }
}
